package com.ruoyi.web.wx.controller;

import java.util.List;

import com.ruoyi.web.wx.entity.EnvirBonusTotal;
import com.ruoyi.web.wx.entity.WxUser;
import com.ruoyi.web.wx.service.IEnvirBonusTotalService;
import com.ruoyi.web.wx.service.IWxUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 环保金总数 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-08-31
 */
@Controller
@RequestMapping("/system/envirBonusTotal")
public class EnvirBonusTotalController extends BaseController
{
    private String prefix = "system/envirBonusTotal";
	
	@Autowired
	private IEnvirBonusTotalService envirBonusTotalService;
	@Autowired
	private IWxUserService wxUserService;
	
	@RequiresPermissions("system:envirBonusTotal:view")
	@GetMapping()
	public String envirBonusTotal()
	{
	    return prefix + "/envirBonusTotal";
	}

	/**
	 * 查询环保金总数列表
	 */
	@RequiresPermissions("system:envirBonusTotal:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(WxUser wxUser)
	{
		startPage();
		List<WxUser> wxUsers = wxUserService.selectWxUserList(wxUser);
		/* List<EnvirBonusTotal> list = envirBonusTotalService.selectEnvirBonusTotalList(envirBonusTotal);*/
		return getDataTable(wxUsers);
	}
	
	
	/**
	 * 导出环保金总数列表
	 */
	@RequiresPermissions("system:envirBonusTotal:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(EnvirBonusTotal envirBonusTotal)
    {
    	List<EnvirBonusTotal> list = envirBonusTotalService.selectEnvirBonusTotalList(envirBonusTotal);
        ExcelUtil<EnvirBonusTotal> util = new ExcelUtil<EnvirBonusTotal>(EnvirBonusTotal.class);
        return util.exportExcel(list, "envirBonusTotal");
    }
	
	/**
	 * 新增环保金总数
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存环保金总数
	 */
	@RequiresPermissions("system:envirBonusTotal:add")
	@Log(title = "环保金总数", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(EnvirBonusTotal envirBonusTotal)
	{		
		return toAjax(envirBonusTotalService.insertEnvirBonusTotal(envirBonusTotal));
	}

	/**
	 * 修改环保金总数
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") String id, ModelMap mmap)
	{
		EnvirBonusTotal envirBonusTotal = envirBonusTotalService.selectEnvirBonusTotalById(id);
		mmap.put("envirBonusTotal", envirBonusTotal);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存环保金总数
	 */
	@RequiresPermissions("system:envirBonusTotal:edit")
	@Log(title = "环保金总数", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(EnvirBonusTotal envirBonusTotal)
	{		
		return toAjax(envirBonusTotalService.updateEnvirBonusTotal(envirBonusTotal));
	}
	
	/**
	 * 删除环保金总数
	 */
	@RequiresPermissions("system:envirBonusTotal:remove")
	@Log(title = "环保金总数", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(envirBonusTotalService.deleteEnvirBonusTotalByIds(ids));
	}
	/**
	 * 查询环保金总数列表
	 */
	@RequiresPermissions("system:envirBonusTotal:list")
	@GetMapping("/detailed")
	public String detaileds(String wxUserId, ModelMap mmap)
	{
		WxUser wxUser = wxUserService.selectWxUserById(wxUserId);
		mmap.put("wxUser",wxUser);
		return prefix + "/envirBonusdetailed";
	}
	/**
	 * 查询环保金总数列表
	 */
	@RequiresPermissions("system:envirBonusTotal:list")
	@PostMapping("/detailedList")
	@ResponseBody
	public TableDataInfo detailedList(String wxUserId)
	{
		startPage();
		EnvirBonusTotal envirBonusTotal = new EnvirBonusTotal();
		envirBonusTotal.setWxUserId(wxUserId);
		List<EnvirBonusTotal> list = envirBonusTotalService.selectEnvirBonusTotalList(envirBonusTotal);
		for (EnvirBonusTotal bonusTotal : list) {
			if ("2".equals(bonusTotal.getType())) {
				Double money = bonusTotal.getMoney();
				money=-money;
				bonusTotal.setMoney(money);
			}
		}
		return getDataTable(list);
	}

}
